///--------------------------------------------------
/**
 *
 *      Hand Gesture Recognition System
 *
 */
//--------------------------------------------------
/**
 * //HGR_GUI CLASS//
 * Librería de captura, pre-procesamiento y procesamiento del sistema
 *
 * @author  Edwin Cobos & Cesar Murcia & Wilson Sarmiento
 * @version HGR_v1.5
 *
 * Revisado: 22/02/12
 */
//--------------------------------------------------
//PACKAGE//
package HGR;
//IMPORT//
import OpenCV.cv;
import hmm.Model;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import javax.media.opengl.awt.GLJPanel;
import javax.swing.UIManager;
//--------------------------------------------------
/**
 *HGR Class Integra los procesos de captura y procesamiento del <b>Hand Gesture Recognition System</b>
 */
public class HGR_gui extends javax.swing.JFrame
{


    //--------------------------------------------------

    //--------------------------------------------------
    //private RTData datos;
    private CamCapture Camera;
    private Listener cameraThread;    
    private static Model[] Models;
    private static int GestureActive;
    private static float ContrastBg;
    private static float ContrastFg;
    private static float ThresholdBgS;
    private static int HistogramsSpeed;
    private static Descriptor[] Descriptors;
    private static int HistogramsLenght;
    private static ArrayList<Integer> observations;
    public static OGL Graphic3D;    
    public static int count;
    public static int inWidth;
    public static int inHeight;
    public static boolean currentGest;
    public static HGR_gui HGR_window;
    
    public static int tra=-1;
    public static int eje=-1;      

    //--------------------------------------------------
    /**
     * Creates new form HGR_gui
     */
    public HGR_gui()
    {
        GestureActive = 0;
        cv.loadHighgui();
        cv.loadCv();
        cv.loadCxcore();       
        initComponents();
        inWidth = 320;
        inHeight = 240;
        ContrastBg = (((Float)(ContrasteSp.getValue())).floatValue());
        //ContrastFg = (((Float)(ContrasteFg.getValue())).floatValue());
        ThresholdBgS = ((float)((((Integer)(UmbralBgSl.getValue())).intValue())/100.0f));
        UmbraBgVal.setText(String.valueOf(ThresholdBgS));
        HistogramsLenght = 0;
        HistogramsSpeed = ((Integer)(VelocidadSp.getValue())).intValue();
        Descriptors = new Descriptor[HistogramsSpeed];
        observations = new ArrayList<Integer>();        
        count = 0;
        currentGest=false;

        LoadModels();

        Graphic3D = new OGL(480,320);
        GLJPanel canvas = new GLJPanel();
        canvas.setPreferredSize(new Dimension(Graphic3D.width, Graphic3D.heigth));
        canvas.addGLEventListener(Graphic3D);
        PanelOGL.add(canvas);
    }
    //--------------------------------------------------
    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        IniciarBtn = new javax.swing.JButton();
        CamaraFrame = new javax.swing.JLabel();
        UmbralBgSl = new javax.swing.JSlider();
        BgsFrame = new javax.swing.JLabel();
        ActualizarBg = new javax.swing.JButton();
        PausaBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        VelocidadSp = new javax.swing.JSpinner();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        UmbraBgVal = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        ContrasteSp = new javax.swing.JSpinner();
        PanelOGL = new javax.swing.JPanel();
        jSeparator3 = new javax.swing.JSeparator();
        out_tex = new javax.swing.JLabel();
        VisCheck = new javax.swing.JCheckBox();
        out_tex_1 = new javax.swing.JLabel();
        out_state = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        GestoTextA1 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        Com_tra = new javax.swing.JRadioButton();
        Com_eje = new javax.swing.JRadioButton();
        Com_aum = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Hand Gesture Recognition");
        setBackground(java.awt.Color.darkGray);
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(800, 630));
        setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(null);

        IniciarBtn.setText("Iniciar");
        IniciarBtn.setToolTipText("Iniciar Captura");
        IniciarBtn.setMinimumSize(new java.awt.Dimension(71, 23));
        IniciarBtn.setPreferredSize(new java.awt.Dimension(71, 23));
        IniciarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IniciarBtnActionPerformed(evt);
            }
        });
        getContentPane().add(IniciarBtn);
        IniciarBtn.setBounds(20, 50, 71, 23);

        CamaraFrame.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        CamaraFrame.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        CamaraFrame.setDebugGraphicsOptions(javax.swing.DebugGraphics.BUFFERED_OPTION);
        CamaraFrame.setDoubleBuffered(true);
        CamaraFrame.setFocusable(false);
        CamaraFrame.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        CamaraFrame.setMaximumSize(new java.awt.Dimension(320, 240));
        getContentPane().add(CamaraFrame);
        CamaraFrame.setBounds(420, 34, 170, 130);

        UmbralBgSl.setPaintLabels(true);
        UmbralBgSl.setPaintTicks(true);
        UmbralBgSl.setSnapToTicks(true);
        UmbralBgSl.setValue(30);
        UmbralBgSl.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                UmbralBgSlStateChanged(evt);
            }
        });
        getContentPane().add(UmbralBgSl);
        UmbralBgSl.setBounds(10, 115, 146, 30);

        BgsFrame.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        BgsFrame.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        BgsFrame.setFocusable(false);
        BgsFrame.setMaximumSize(new java.awt.Dimension(320, 240));
        getContentPane().add(BgsFrame);
        BgsFrame.setBounds(600, 34, 170, 130);

        ActualizarBg.setText("Actualizar BG");
        ActualizarBg.setToolTipText("Actualizar Background");
        ActualizarBg.setEnabled(false);
        ActualizarBg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActualizarBgActionPerformed(evt);
            }
        });
        getContentPane().add(ActualizarBg);
        ActualizarBg.setBounds(180, 50, 110, 25);

        PausaBtn.setText("Pausa");
        PausaBtn.setToolTipText("Pausar captura");
        PausaBtn.setEnabled(false);
        PausaBtn.setMaximumSize(new java.awt.Dimension(71, 23));
        PausaBtn.setMinimumSize(new java.awt.Dimension(71, 23));
        PausaBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PausaBtnActionPerformed(evt);
            }
        });
        getContentPane().add(PausaBtn);
        PausaBtn.setBounds(100, 50, 70, 25);

        jLabel1.setText("Camara");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(420, 20, 100, 16);

        jLabel2.setText("Background Substraction");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(600, 20, 230, 16);

        VelocidadSp.setModel(new javax.swing.SpinnerNumberModel(3, 1, 10, 1));
        VelocidadSp.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                VelocidadSpStateChanged(evt);
            }
        });
        getContentPane().add(VelocidadSp);
        VelocidadSp.setBounds(260, 115, 48, 25);
        getContentPane().add(jSeparator2);
        jSeparator2.setBounds(190, 550, 420, 10);

        jLabel3.setText("Velocidad");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(260, 95, 70, 16);

        jLabel4.setText("Umbral Bg:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(20, 95, 80, 16);

        UmbraBgVal.setText("0");
        getContentPane().add(UmbraBgVal);
        UmbraBgVal.setBounds(80, 95, 60, 16);

        jLabel5.setText("Contraste Bg");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(170, 95, 80, 16);

        ContrasteSp.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(1.0f), Float.valueOf(0.1f), Float.valueOf(2.0f), Float.valueOf(0.1f)));
        ContrasteSp.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                ContrasteSpStateChanged(evt);
            }
        });
        getContentPane().add(ContrasteSp);
        ContrasteSp.setBounds(180, 115, 48, 25);

        PanelOGL.setBorder(javax.swing.BorderFactory.createTitledBorder("Salida"));
        PanelOGL.setPreferredSize(new java.awt.Dimension(720, 540));
        getContentPane().add(PanelOGL);
        PanelOGL.setBounds(150, 180, 510, 360);

        jSeparator3.setToolTipText("");
        jSeparator3.setName("Sep_1"); // NOI18N
        getContentPane().add(jSeparator3);
        jSeparator3.setBounds(3, 80, 393, 10);

        out_tex.setText("Presione iniciar para comenzar");
        out_tex.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        getContentPane().add(out_tex);
        out_tex.setBounds(20, 27, 370, 16);

        VisCheck.setSelected(true);
        VisCheck.setText("Visualizar");
        VisCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VisCheckActionPerformed(evt);
            }
        });
        getContentPane().add(VisCheck);
        VisCheck.setBounds(295, 50, 80, 25);

        out_tex_1.setText("0");
        getContentPane().add(out_tex_1);
        out_tex_1.setBounds(440, 560, 30, 16);

        out_state.setText("En Espera...");
        getContentPane().add(out_state);
        out_state.setBounds(360, 560, 80, 16);

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Historial Gestos"));
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setHorizontalScrollBar(null);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(50, 96));

        GestoTextA1.setColumns(10);
        GestoTextA1.setEditable(false);
        GestoTextA1.setRows(10);
        GestoTextA1.setBorder(null);
        GestoTextA1.setOpaque(false);
        jScrollPane1.setViewportView(GestoTextA1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(0, 180, 100, 360);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Controles"));
        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 400, 170);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Visualización"));
        getContentPane().add(jPanel2);
        jPanel2.setBounds(410, 0, 370, 170);

        buttonGroup1.add(Com_tra);
        Com_tra.setText("Trasformación");
        getContentPane().add(Com_tra);
        Com_tra.setBounds(670, 250, 111, 25);

        buttonGroup1.add(Com_eje);
        Com_eje.setText("Eje");
        getContentPane().add(Com_eje);
        Com_eje.setBounds(670, 280, 110, 25);

        buttonGroup1.add(Com_aum);
        Com_aum.setText("+/-");
        getContentPane().add(Com_aum);
        Com_aum.setBounds(670, 310, 110, 25);

        pack();
    }// </editor-fold>//GEN-END:initComponents
   
    //--------------------------------------------------
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing

        if(cameraThread != null && cameraThread.isAlive())
        {
            cameraThread.Finalize();
        }
        
        if(Camera != null)
            Camera = null;
        
        System.out.println("Free Camera");        
        this.dispose();
        System.exit(0);
    }//GEN-LAST:event_formWindowClosing
    //--------------------------------------------------
    private void IniciarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IniciarBtnActionPerformed

        out_tex.setText("Inicio del Sistema... espere...");

        if(Camera != null)
            Camera = null;
        if(cameraThread != null)
            cameraThread = new Listener();
        
        Camera = new CamCapture();
        if(Camera.IsCamera())
        {
            IniciarBtn.setEnabled(false);
            ActualizarBg.setEnabled(true);
            PausaBtn.setEnabled(true);
            cameraThread = new Listener();
            cameraThread.setListenable(Camera);            
            cameraThread.start();
        }
        else
        {
            out_tex.setText("No Camera Connected");
        }        
    }//GEN-LAST:event_IniciarBtnActionPerformed
    //--------------------------------------------------
    private void PausaBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PausaBtnActionPerformed
        if(cameraThread != null)
        {
            cameraThread.Pause();
        }
        

    }//GEN-LAST:event_PausaBtnActionPerformed
    //--------------------------------------------------
    private void ActualizarBgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ActualizarBgActionPerformed
        Camera.updateBackGround();
    }//GEN-LAST:event_ActualizarBgActionPerformed
    //--------------------------------------------------    //--------------------------------------------------
    private void UmbralBgSlStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_UmbralBgSlStateChanged
        ThresholdBgS = ((float)((((Integer)(UmbralBgSl.getValue())).intValue())/100.0f));
        UmbraBgVal.setText(String.valueOf(ThresholdBgS));
    }//GEN-LAST:event_UmbralBgSlStateChanged
    //--------------------------------------------------
    private void VelocidadSpStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_VelocidadSpStateChanged
        // TODO add your handling code here:
        HistogramsSpeed = ((Integer)(VelocidadSp.getValue())).intValue();
        Descriptors = new Descriptor[HistogramsSpeed];
    }//GEN-LAST:event_VelocidadSpStateChanged
    //--------------------------------------------------
    private void ContrasteSpStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ContrasteSpStateChanged
        ContrastBg = (((Float)(ContrasteSp.getValue())).floatValue());
    }//GEN-LAST:event_ContrasteSpStateChanged

    private void VisCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VisCheckActionPerformed
        // TODO add your handling code here:
        if(cameraThread != null && !HGR_gui.VisCheck.isSelected())
        {
            CamDisplay show;
            float[] b= new float[inWidth*inHeight];
            for(int i=0; i<b.length; i++)
                b[i]=0.0f;

            show = new CamDisplay(new Frame(b, -1, inWidth, inHeight), HGR_gui.CamaraFrame);
            show.start();

            show = new CamDisplay(new Frame(b, -1, inWidth, inHeight), HGR_gui.BgsFrame);
            show.start();
        }
    }//GEN-LAST:event_VisCheckActionPerformed
    //--------------------------------------------------
    public void LoadModels()
    {
        ArrayList<String> ModelFile = new ArrayList<String>();
        Core.ListDir("Modelos", ModelFile, ".hmm");
        //Collections.shuffle(ModelFile);
        //System.out.println(ModelFile);
        Models = new Model[ModelFile.size()];
        int i;
        for(i=0; i<ModelFile.size(); i++)
        {
            Models[i] = ReadModelFile(ModelFile.get(i), 15);
        }
    }
    //--------------------------------------------------
    public static float GetContrastBg()
    {
        return ContrastBg;
    }
    //--------------------------------------------------
    public static float GetContrastFg()
    {
        return ContrastFg;
    }
    //--------------------------------------------------
    public static int GetHistogramsSpeed()
    {
        return HistogramsSpeed;
    }
    //--------------------------------------------------
    public static float GetThresholdBgS()
    {
        return ThresholdBgS;
    }
    //--------------------------------------------------
    public static Descriptor GetDescriptor(int i)
    {
        return Descriptors[i];
    }
    //--------------------------------------------------
    public static void SetDescriptor(Descriptor Desc, int i)
    {
        Descriptors[i] = Desc;
    }
    //-------------------------------------------------- 
    public static void clearDescriptor()
    {
        Descriptors = new Descriptor[HistogramsSpeed];
    }
    //-------------------------------------------------- 
    public static int GetHistogramsLenght()
    {
        return HistogramsLenght;
    }
    //-------------------------------------------------- 
    public static void SetHistogramsLenght(int hl)
    {
        HistogramsLenght = hl;
    }
    //--------------------------------------------------
    public static int GetGestureActive()
    {
        return GestureActive;
    }
    //--------------------------------------------------
    public static void SetGestureActive(int ga)
    {
        GestureActive = ga;
    }
    //-------------------------------------------------- 
    public static void SetObservations(int angle)
    {
        observations.add(angle);
        out_tex_1.setText(String.valueOf(observations.size()));

    }
    //--------------------------------------------------
    public static void ClearObservations()
    {
        out_state.setText("Fin Gesto");
        observations.clear();
        out_tex_1.setText(String.valueOf(observations.size()));

    }
    //-------------------------------------------------- 
    public static ArrayList<Integer> GetObservations()
    {
        return observations;
    }
    //--------------------------------------------------
    public static void Gesture(int gesto)
    {  
       /* aum  0
        * dism 1
        * esc  2
        * rot  3
        * tra  4
        * x    5
        * y    6
        * z    7
        */        
        
        switch(gesto)
        {
            //+/-
            //Aumentar
            case 0:
                
                //Escalar                
                if(tra==2)
                {
                    //EjeX
                    if(eje==5)
                    {
                        Graphic3D.escx += 0.1;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        Graphic3D.escy += 0.1;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        Graphic3D.escz += 0.1;
                    } 
                }
                //Rotar
                if(tra==3)
                {
                    //EjeX
                    if(eje==5)
                    {
                        Graphic3D.rotx += 10.0;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        Graphic3D.roty += 10.0;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        Graphic3D.rotz += 10.0;
                    }
                }               
                
                //Trasladar
                if(tra==4)
                {
                    //EjeX
                    if(eje==5)
                    {
                        if(Graphic3D.trax < 10)
                            Graphic3D.trax += 1.0;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        if(Graphic3D.tray < 10)
                            Graphic3D.tray += 1.0;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        if(Graphic3D.traz < 10)
                            Graphic3D.traz += 1.0;
                    }
                }
                GestoTextA1.setText("Aumentar\n"+GestoTextA1.getText());
                UpdateJogl();                
                break;
            //Disminuir    
            case 1:
                
                 //Escalar                
                if(tra==2)
                {
                    //EjeX
                    if(eje==5)
                    {
                        Graphic3D.escx -= 0.1;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        Graphic3D.escy -= 0.1;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        Graphic3D.escz -= 0.1;
                    } 
                }
                //Rotar
                if(tra==3)
                {
                    //EjeX
                    if(eje==5)
                    {
                        Graphic3D.rotx -= 10.0;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        Graphic3D.roty -= 10.0;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        Graphic3D.rotz -= 10.0;
                    }
                }               
                
                //Trasladar
                if(tra==4)
                {
                    //EjeX
                    if(eje==5)
                    {
                        if(Graphic3D.trax > -10)
                            Graphic3D.trax -= 1.0;
                    }
                    //EjeY
                    if(eje==6)
                    {
                        if(Graphic3D.tray > -10)
                            Graphic3D.tray -= 1.0;
                    }
                    
                    //EjeZ
                    if(eje==7)
                    {
                        if(Graphic3D.traz > -10)
                            Graphic3D.traz -= 1.0;
                    }
                }
                GestoTextA1.setText("Disminuir\n"+GestoTextA1.getText());
                UpdateJogl();
                break;
            //Transformación  
            case 2:
                tra = gesto; 
                GestoTextA1.setText("Escalar\n"+GestoTextA1.getText());
            break; 
            case 3:
                tra = gesto; 
                GestoTextA1.setText("Rotar\n"+GestoTextA1.getText());
            break;             
            case 4:
                tra = gesto; 
                GestoTextA1.setText("Trasladar\n"+GestoTextA1.getText());
            break; 
                
            //Eje
            case 5:
                eje = gesto;
                GestoTextA1.setText("Eje X\n"+GestoTextA1.getText());
            break;              
            case 6:
                eje = gesto;
                GestoTextA1.setText("Eje Y\n"+GestoTextA1.getText());
            break;               
            case 7:
                eje = gesto;
                GestoTextA1.setText("Eje Z\n"+GestoTextA1.getText());
            break;   
                
                
                
            
            
            
            /*case 0:
                //Graphic3D.roty += 20;
                UpdateJogl();
                GestoTextA1.setText("Aumentar\n"+GestoTextA1.getText());
                break;

            case 1://Escalar
                Graphic3D.sc += 0.1;
                UpdateJogl();
                GestoTextA1.setText("Escalar\n"+GestoTextA1.getText());
                break;

            case 2:
                Graphic3D.roty += 20;
                UpdateJogl();                
                GestoTextA1.setText("Rotación\n"+GestoTextA1.getText());
                break;

            case 3:
                boolean or = false;
                if(Graphic3D.trax > 10)
                    or = true;
                
                if(Graphic3D.trax < -10)
                    or = false;

                if(or == true)
                    Graphic3D.trax -= 1.0;
                else
                    Graphic3D.trax += 1.0;

                UpdateJogl();                
                GestoTextA1.setText("Trasladar\n"+GestoTextA1.getText());

                break;

            case 4:
                //Graphic3D.roty += 20;
                UpdateJogl();                
                GestoTextA1.setText("Eje X\n"+GestoTextA1.getText());
                break;      */      
        }
    }
    //--------------------------------------------------
    public static Model getModels(int p)
    {
       return Models[p];
    }
    public static void UpdateJogl()
    {
        PanelOGL.repaint();
        //PanelOGL.updateUI();
    }
    //--------------------------------------------------
    /**
     * Lee los archivos y devuelve el modelo de Markov
     * @param filename Nombre del archivo
     * @param DivAngle Número de división de ángulos
     * @return Modelo de Markov
     */
    public Model ReadModelFile(String filename, int DivAngle)
    {
        
        File archivo = null;
        InputStreamReader fr = null;
        BufferedReader br = null;
        int n=0;
        String[] m = new String[0];
        float[][] a = new float[n][n];
        float[][] b = new float[n][360/DivAngle];
        float[] pi = new float[n];
        try
        {
            archivo = new File(filename);            
            fr = new InputStreamReader(new FileInputStream(archivo), "UTF-8");
            br = new BufferedReader(fr);
            // Lectura del fichero
            String linea;
            String[] part;
            int l = 0;
            //Mientras halla lineas en el archivo
            while((linea=br.readLine())!=null)
            {
                if(l==0)
                {                    
                    n = (Integer.parseInt(linea));
                    m = new String[360/DivAngle];
                    pi = new float[n];
                    a = new float[n][n];
                    b = new float[n][360/DivAngle];
                }
                if(l==1)
                {                   
                    part = linea.split(" ");
                    for(int i=0; i<360/DivAngle; i++)
                    {
                        m[i]=part[i];
                    }
                    
                }
                if(linea.intern()=="#Pi")
                {
                    linea=br.readLine();
                    part = linea.split(" ");
                    for(int i=0; i<n; i++)
                    {
                        pi[i]=(Float.valueOf(part[i]));
                    }                    
                }
                if(linea.intern()=="#A")
                {
                    for(int i=0; i<n; i++)
                    {
                        linea=br.readLine();
                        part = linea.split(" ");
                        for(int j=0; j<n; j++)
                        {
                        a[i][j]=(Float.valueOf(part[j]));
                        }
                    }                    
                }
                if(linea.intern()=="#B")
                {
                    for(int i=0; i<n; i++)
                    {
                        linea=br.readLine();
                        part = linea.split(" ");
                        for(int j=0; j<m.length; j++)
                        {
                        b[i][j]=(Float.valueOf(part[j]));
                        }
                    }                    
                }
                l++;
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            //Cerrar el Archivo
            try
            {
                if( null != fr )
                {
                    fr.close();
                }
            }
            catch(Exception e2)
            {
                e2.printStackTrace();
            }
        }

        Model lambda = new Model(n, m, a, b, pi);
        return lambda;
    }
    //--------------------------------------------------
    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /*System.out.println(System.getProperty("java.classpath"));
        System.out.println(System.getProperty("java.library.path"));        
        System.out.println(System.getProperty("java.library.path"));*/
        //System.setProperty("java.library.path", "/lib;C:\\OpenCV\\bin\\x64");
        //System.out.println(System.getProperties());

        //System.out.println(System.getProperty("path"));
        //System.out.println(System.getenv());

        //System.console().writer().println("ALGUNAS COSAS");
        
        

        //new ProcessBuilder("path", "C:/OpenCV/bin/x64;");
        try
        {
            UIManager _ui = new UIManager();
            _ui.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel");
        }
        catch(Exception ex){}
        /*for(UIManager.LookAndFeelInfo laf:UIManager.getInstalledLookAndFeels()){
            if("Nimbus".equals(laf.getName()))
                try {
                    UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel");
                } catch (Exception ex) {
            }
        }*/
        
        java.awt.EventQueue.invokeLater
        (
            new Runnable()
            {
                public void run()
                {
                HGR_window = new HGR_gui();
                HGR_window.setVisible(true);                
                }
            }
        );
    }
    //--------------------------------------------------
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ActualizarBg;
    public static javax.swing.JLabel BgsFrame;
    public static javax.swing.JLabel CamaraFrame;
    public static javax.swing.JRadioButton Com_aum;
    public static javax.swing.JRadioButton Com_eje;
    public static javax.swing.JRadioButton Com_tra;
    private javax.swing.JSpinner ContrasteSp;
    public static javax.swing.JTextArea GestoTextA1;
    private javax.swing.JButton IniciarBtn;
    public static javax.swing.JPanel PanelOGL;
    private javax.swing.JButton PausaBtn;
    private javax.swing.JLabel UmbraBgVal;
    private javax.swing.JSlider UmbralBgSl;
    public static javax.swing.JSpinner VelocidadSp;
    public static javax.swing.JCheckBox VisCheck;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    public static javax.swing.JLabel out_state;
    public static javax.swing.JLabel out_tex;
    public static javax.swing.JLabel out_tex_1;
    // End of variables declaration//GEN-END:variables
    //--------------------------------------------------
}
//--------------------------------------------------
//FIN
//--------------------------------------------------